home *** CD-ROM | disk | FTP | other *** search
- //____________________________________________________________
- // Generic.c
- //
- // Copyright © Dan Parks Sydow, 1995
- // From the book:
- // "Graphics and Sound Programming Techniques for the Mac",
- // M&T Books, 1995
-
-
- //____________________________________________________________
-
- #include <Movies.h>
-
- #include "Defines.h"
- #include "DataTypes.h"
- #include "Globals.h"
- #include "Initialize.h"
- #include "WindRecordAccess.h"
- #include "MovieUtilities.h"
- #include "AppleMenu.h"
- #include "FileMenu.h"
- #include "EditMenu.h"
- #include "Generic.h"
-
-
- //____________________________________________________________
-
- void main( void )
- {
- InitializeAllToolboxes();
-
- SetUpMenuBar();
-
- EventLoop();
- }
-
-
- //____________________________________________________________
-
- void EventLoop( void )
- {
- EventRecord theEvent;
- Boolean isControllerEvent;
-
- while ( gDone == false )
- {
- WaitNextEvent( everyEvent, &theEvent, 0, nil );
-
- AdjustAllMenus();
-
- isControllerEvent = UpdateAllOpenMovies( theEvent );
-
- if ( isControllerEvent == false )
- {
- switch ( theEvent.what )
- {
- case activateEvt:
- HandleActivateEvent( theEvent );
- break;
-
- case updateEvt:
- HandleUpdateEvent( theEvent );
- break;
-
- case keyDown:
- HandleKeyDownEvent( theEvent );
- break;
-
- case mouseDown:
- HandleMouseDownEvent( theEvent );
- break;
- }
- }
- }
- }
-
-
- //____________________________________________________________
-
- void AdjustAllMenus( void )
- {
- WindowPtr theWindow;
- MovieController theController;
- MenuHandle theMenu;
-
- theWindow = FrontWindow();
-
- if ( theWindow == nil )
- {
- theMenu = GetMHandle( mFile );
- DisableItem( theMenu, iClose );
- DisableItem( theMenu, iSave );
- DisableItem( theMenu, iSaveAs );
-
- theMenu = GetMHandle( mEdit );
- DisableItem( theMenu, iUndo );
- DisableItem( theMenu, iCut );
- DisableItem( theMenu, iCopy );
- DisableItem( theMenu, iPaste );
- DisableItem( theMenu, iClear );
- DisableItem( theMenu, iSelectAll );
- }
- else
- {
- theMenu = GetMHandle( mFile );
- EnableItem( theMenu, iClose );
- EnableItem( theMenu, iSave );
- EnableItem( theMenu, iSaveAs );
-
- theMenu = GetMenuHandle( mEdit );
- if ( GetWindowType( theWindow ) == kMovieWindowType )
- {
- theController = GetWindowController( theWindow );
- MCSetUpEditMenu( theController, 0, theMenu );
- EnableItem( theMenu, iSelectAll );
- }
- else
- {
- EnableItem( theMenu, iUndo );
- EnableItem( theMenu, iCut );
- EnableItem( theMenu, iCopy );
- EnableItem( theMenu, iPaste );
- EnableItem( theMenu, iClear );
- EnableItem( theMenu, iSelectAll );
- }
- }
- }
-
-
- //____________________________________________________________
-
- void HandleActivateEvent( EventRecord theEvent )
- {
- WindowPtr theWindow;
- Boolean isActivateEvent;
- MovieController theController;
-
- theWindow = (WindowPtr)theEvent.message;
- SetPort( theWindow );
- isActivateEvent = ( theEvent.modifiers & activeFlag ) != 0;
-
- if ( GetWindowType( theWindow ) == kMovieWindowType )
- {
- theController = GetWindowController( theWindow );
- MCActivate( theController, theWindow, isActivateEvent );
- }
- }
-
-
- //____________________________________________________________
-
- void HandleUpdateEvent( EventRecord theEvent )
- {
- WindowPtr theWindow;
-
- theWindow = (WindowPtr)theEvent.message;
- BeginUpdate( theWindow );
- EraseRect( &(theWindow->portRect) );
- // update "nonQuickTime" windows here
- EndUpdate( theWindow );
- }
-
-
- //____________________________________________________________
-
- void HandleKeyDownEvent( EventRecord theEvent )
- {
- short theChar;
- long theMenuAndItem;
-
- theChar = theEvent.message & charCodeMask;
-
- if ( ( theEvent.modifiers & cmdKey ) != 0 )
- {
- if ( theEvent.what != autoKey )
- {
- theMenuAndItem = MenuKey( theChar );
- HandleMenuChoice( theMenuAndItem );
- }
- }
- }
-
-
- //____________________________________________________________
-
- void HandleMouseDownEvent( EventRecord theEvent )
- {
- WindowPtr theWindow;
- short thePart;
- long theMenuAndItem;
-
- thePart = FindWindow( theEvent.where, &theWindow );
-
- switch ( thePart )
- {
- case inMenuBar:
- theMenuAndItem = MenuSelect( theEvent.where );
- HandleMenuChoice( theMenuAndItem );
- break;
-
- case inGoAway:
- if ( TrackGoAway( theWindow, theEvent.where ) )
- {
- if ( GetWindowType( theWindow ) != kMovieWindowType )
- {
- DisposeWindow( theWindow );
- --gWindowCount;
- }
- else
- CloseMovieAndFile( theWindow );
- }
- break;
-
- case inDrag:
- DragWindow( theWindow, theEvent.where, &qd.screenBits.bounds );
- break;
-
- case inContent:
- SelectWindow( theWindow );
- break;
- }
- }
-
-
- //____________________________________________________________
-
- void HandleMenuChoice( long theMenuAndItem )
- {
- short theMenu;
- short theMenuItem;
-
- if ( theMenuAndItem != 0 )
- {
- theMenu = HiWord( theMenuAndItem );
- theMenuItem = LoWord( theMenuAndItem );
-
- switch ( theMenu )
- {
- case mApple:
- HandleAppleChoice( theMenuItem );
- break;
-
- case mFile:
- HandleFileChoice( theMenuItem );
- break;
-
- case mEdit:
- HandleEditChoice( theMenuItem );
- break;
- }
- HiliteMenu(0);
- }
- }
-
-
- //____________________________________________________________
-
- void HandleAppleChoice( short theMenuItem )
- {
- switch ( theMenuItem )
- {
- case iAbout:
- HandleAppleMenuAboutItem();
- break;
-
- default:
- HandleAppleMenuDefaultItem( theMenuItem );
- break;
- }
- }
-
-
- //____________________________________________________________
-
- void HandleFileChoice( short theMenuItem )
- {
- switch ( theMenuItem )
- {
- case iOpen:
- HandleFileMenuOpenItem();
- break;
-
- case iClose:
- HandleFileMenuCloseItem();
- break;
-
- case iSave:
- HandleFileMenuSaveItem();
- break;
-
- case iSaveAs:
- HandleFileMenuSaveAsItem();
- break;
-
- case iQuit:
- HandleFileMenuQuitItem();
- break;
- }
- }
-
-
- //____________________________________________________________
-
- void HandleEditChoice( short theMenuItem )
- {
- switch ( theMenuItem )
- {
- case iUndo:
- HandleEditMenuUndoItem();
- break;
-
- case iCut:
- HandleEditMenuCutItem();
- break;
-
- case iCopy:
- HandleEditMenuCopyItem();
- break;
-
- case iPaste:
- HandleEditMenuPasteItem();
- break;
-
- case iClear:
- HandleEditMenuClearItem();
- break;
-
- case iSelectAll:
- HandleEditMenuSelectAllItem();
- break;
- }
- }
-
-
-